// import './roleNew.scss'
import '../../static/font/iconfont.css'
import { Form, Input, Button, Select, Image, message, Modal } from 'antd';
import { ExclamationCircleOutlined } from '@ant-design/icons';
import Avatar from './Upload'
import React from 'react'
import './tem.scss'
import { useEffect, useState } from 'react';
import http from '../../utils/http'
const { Option } = Select;
const { confirm } = Modal;
const layout = {
    labelCol: {
        span: 6,
    },
    wrapperCol: {
        span: 14,
    },
};
const tailLayout = {
    wrapperCol: {
        offset: 8,
        span: 16,
    },
};
//下拉
// let provinceData = ['Zhejiang', 'lll'];
const TenNew = ({ setState }) => {
    //返回页面
    // const [cities, setCities] = React.useState(provinceData);
    const [selectdata, setSelectdata] = useState([])
    useEffect(() => {
        let a = []
        http({
            url: '/Peree_Person/PersonInsertInterface',
            method: 'post',
        }).then((res) => {
            if (res.code == 200) {
                //对数据进行处理
                let arr = res.data.map((v, i) => {
                    return {
                        key: v.perId,
                        name: v.perName
                    }
                })
                console.log(arr)
                setSelectdata(arr)
                console.log(selectdata)
            }
        })

    }, [])
    //下拉

    // const handleProvinceChange = value => {
    //     // setCities(cityData[value]);
    //     // setSecondCity(cityData[value][0]);
    // };

    // const onSecondCityChange = value => {
    //     setSecondCity(value);
    // };


    const backCar = () => {
        setState(1)
    }
    const quxiao = () => {
        confirm({
            icon: <ExclamationCircleOutlined />,
            content: '您确定离开此页面吗？',
            cancelText: '取消',
            okText: '确定',
            onOk() {
                //   console.log('OK');
                backCar()
            },
            onCancel() {
                console.log('Cancel');
            },
        });
    }
    const [form1] = Form.useForm();
    const [form2] = Form.useForm();

    const onFinish = (values) => {
        console.log(values)
        // for (let key in values) {
        //     a[key] = values[key]
        // }
        // for (let key in form1.getFieldsValue(true)) {
        //     a[key] = form1.getFieldsValue(true)[key]
        // }
        // for (let key in form2.getFieldsValue(true)) {
        //     a[key] = form2.getFieldsValue(true)[key]
        // }
        // console.log(a)
        http({
            url: '/Peree_Person/InsertPersonInfo',
            method: 'post',
            params: values,
        }).then((res) => {
            console.log(res)
            if (res.code == 200) {
                setState(1)
                message.success('添加成功！');
            }
            else {
                message.error('添加失败！')
            }
        })
    };

    return (
        <div className="xinzeng">
            <div style={{ height: '800px' }}>
                <div className='tit'>
                    <div>
                        <div>
                            <div></div>
                            <div>人员信息新增</div>
                        </div>
                    </div>
                    <div>
                        <span className="iconfont icon-a-16guanbi" onClick={backCar}></span>
                    </div>
                </div>
                <hr></hr>
                <div className='content'>
                    <div>
                        <p>人员基本信息:</p>
                        <Form {...layout} form={form1} style={{ height: '600px' }} name="control-hooks" onFinish={onFinish}>
                            <Form.Item
                                name="personName"
                                label="人员姓名"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Input placeholder='请输入人员姓名' />
                            </Form.Item>
                            <Form.Item
                                name="personPhone"
                                label="联系方式"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Input placeholder='请输入联系方式' />
                            </Form.Item>
                            <Form.Item
                                name="personSex"
                                label="人员性别"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Select
                                    placeholder="请选择"
                                    allowClear
                                >
                                    <Option value="0">男</Option>
                                    <Option value="1">女</Option>
                                </Select>
                            </Form.Item>
                            <Form.Item
                                name="personEaducation"
                                label="人员学历"
                            >
                                <Input placeholder='请输入人员学历' />
                            </Form.Item>
                            <Form.Item
                                name="personVx"
                                label="绑定微信号"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            ><Input />
                            </Form.Item>
                            <Form.Item
                                name="logPassword"
                                label="密码"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            ><Input />
                            </Form.Item>
                            <Form.Item
                                name="perId"
                                label="租户名称"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Select placeholder="请选择租户">
                                    {selectdata.map((item) =>
                                        <Option value={item.key} key={item.key}>{item.name}</Option>
                                    )}
                                </Select>
                            </Form.Item>
                            <Form.Item
                                name="personType"
                                label="人员类型"
                                rules={[
                                    {
                                        required: true,
                                    },
                                ]}
                            >
                                <Select
                                    placeholder="请选择"
                                    allowClear
                                >
                                    <Option value="0">负责人</Option>
                                    <Option value="1">普通员工</Option>
                                </Select>
                            </Form.Item>
                            <Form.Item
                                name="personPhoto"
                                label="人脸照片"
                            // rules={[
                            //     {
                            //         required: true,
                            //     },
                            // ]}
                            >
                                <Avatar></Avatar>
                            </Form.Item>
                            <Form.Item {...tailLayout} className='mybutton'>
                                <div className='btn'>
                                    <Button type="primary" htmlType="submit">
                                        保存
                                    </Button>
                                    <Button onClick={quxiao}>
                                        取消
                                    </Button>
                                </div>
                            </Form.Item>
                        </Form>

                    </div>
                    {/* <div>
                        <p>人员所属信息:</p>
                        <div>
                            <div>
                                <Form {...layout} form={form2} name="control-hooks" onFinish={onFinish}>
                                    <Form.Item
                                        name="per_type"
                                        label="租户类型"
                                        rules={[
                                            {
                                                required: true,
                                            },
                                        ]}
                                    >
                                        <Select
                                            placeholder="请选择"
                                            allowClear
                                        >
                                            <Option value="0">企业</Option>
                                            <Option value="1">租户</Option>
                                        </Select>
                                    </Form.Item>
                                    <Form.Item
                                        name="person_name"
                                        label="负责人姓名"
                                        rules={[
                                            {
                                                required: true,
                                            },
                                        ]}
                                    >
                                        <Input />
                                    </Form.Item>
                                    <Form.Item
                                        name="ten_serialint"
                                        label="所属楼宇"
                                        rules={[
                                            {
                                                required: true,
                                            },
                                        ]}
                                    >
                                        <Select
                                            placeholder="请选择"
                                            allowClear
                                        >
                                            <Option value="A1幢">A1幢</Option>
                                            <Option value="B2幢">B2幢</Option>
                                            <Option value="C3幢">C3幢</Option>
                                        </Select>
                                    </Form.Item>

                                    <Form.Item
                                        name="per_logo"
                                        label="企业Logo"
                                    // rules={[
                                    //     {
                                    //         required: true,
                                    //     },
                                    // ]}
                                    >
                                        <Avatar></Avatar>
                                    </Form.Item>
                                  
                                </Form>
                            </div>
                            <div>
                                <Form {...layout} form={form3} name="control-hooks" onFinish={onFinish}>
                                    
                                    <Form.Item
                                        name="person_phone"
                                        label="联系方式"
                                        rules={[
                                            {
                                                required: true,
                                            },
                                        ]}
                                    >
                                        <Input />
                                    </Form.Item>
                                    <Form.Item
                                        name="room_no"
                                        label="房间名称"
                                        rules={[
                                            {
                                                required: true,
                                            },
                                        ]}
                                    >
                                        <Input />
                                    </Form.Item>
                                    
                                </Form>
                            </div>
                        </div>
                    </div> */}
                </div>
                {/* <div className='building_button_two' style={{ textAlign: ' center' }}>
                    <Button type="primary" htmlType="submit" style={{ margin: '0px 5px' }}>
                        保存
                    </Button>
                    <Button style={{ margin: '0px 5px' }}>
                        取消
                    </Button>
                </div> */}
            </div>
        </div >)
}
export default TenNew